package structures;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import javax.faces.model.SelectItem;

import manager.KysManager;
import constants.EnvironmentConstants;
import exception.IBToolsException;

public class DeployInfo implements Serializable {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1682175721095746688L;
	
	private String componentOid;
	private String version;
	
	private List<SelectItem> componentVersionList;
	private String selectedVersion;

	public DeployInfo() {
		super();
		// TODO Auto-generated constructor stub
	}

	public void loadComponentVersions(Integer environment) throws IBToolsException {
		if(componentOid == null)
			componentVersionList = new ArrayList<SelectItem>();
		else {
			if(componentVersionList == null){
				componentVersionList = new ArrayList<SelectItem>();
			}
			componentVersionList.clear();
			List<String> versions = KysManager.getDeployEntryVersionList(
					EnvironmentConstants.CORE, 
					EnvironmentConstants.ENV_DEPLOYENV.get(environment),
					EnvironmentConstants.ENV_SOURCEDB.get(environment),
					componentOid);
			versions.remove(0);
			for (String version : versions) {
	            componentVersionList.add(new SelectItem(
	            		version, version));
			}
		}
	}

	public String getComponentOid() {
		return componentOid;
	}

	public void setComponentOid(String componentOid) {
		this.componentOid = componentOid;
	}

	public String getVersion() {
		return version;
	}

	public void setVersion(String version) {
		this.version = version;
	}
	
	public List<SelectItem> getComponentVersionList() {
		return componentVersionList;
	}

	public void setComponentVersionList(List<SelectItem> componentVersionList) {
		this.componentVersionList = componentVersionList;
	}

	public String getSelectedVersion() {
		return selectedVersion;
	}

	public void setSelectedVersion(String selectedVersion) {
		this.selectedVersion = selectedVersion;
	}
	
}
